package exanination;

import java.util.Scanner;

//输入某年某月某日，判断这天是一年中的第几天？（注意闰年和平年的区别）
public class Date {
    public static void main(String[] args) {
        Scanner sca = new Scanner(System.in);
        int year;
        System.out.println("请输入年份：");
        year = sca.nextInt();
        int mouth;
        System.out.println("请输入月份：");
        mouth = sca.nextInt();
        int day;
        System.out.println("请输入日期：");
        day = sca.nextInt();
        int date=getDate(year,mouth,day);
        System.out.println(year+"-"+mouth+"-"+day+"是一年中的第"+date+"天");
    }
    public static int getDate(int year,int month,int day){
        int []monthDate = {31,28,31,30,31,30,31,31,30,31,30,31};
        if(isLeapYear(year)){
            monthDate[1]=29;
        }
        int date=0;
        for (int i = 0; i < month-1; i++) {
            date += monthDate[i];
        }
        date += day;
        return date;
    }
    public static boolean isLeapYear(int year){
        if (year % 4 != 0) {
            return false;
        } else if (year % 100 != 0) {
            return true;
        } else if (year % 400 != 0) {
            return false;
        } else {
            return true;
        }
    }
}
